/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-11-14
 * Time: 10:36
 */
public class SumCalculator {
    public static void main(String[] args) {
        int[] arr = {3, 8, 1, 4, 9, 2, 6, 5, 7};
        int sum = calculateSum(arr, 0, arr.length - 1);
        System.out.println("Sum: " + sum);
    }

    static int calculateSum(int[] arr, int low, int high) {
        if (low == high) {
            return arr[low];
        } else {
            int mid = (low + high) / 2;
            int leftSum = calculateSum(arr, low, mid);
            int rightSum = calculateSum(arr, mid + 1, high);
            return leftSum + rightSum;
        }
    }
}
